package com.java.base.string;

import java.io.UnsupportedEncodingException;

public class StringCharsetTest {

    public static void main(String[] args) throws UnsupportedEncodingException {
        //GBK中ASCII是以0开头的一个byte，中文是以两个1开头的byte
        byte[] gbk = {
                (byte) 0xB0, (byte) 0xA2,
                (byte) 0xd0, (byte) 0xc2,
                0x01
        };
        System.out.println(new String(gbk, "GBK"));

        //utf-8是变长编码，以开头几个1代表占几个byte，最多6个byte,unicode相当于字典，utf8/utf32等是根据unicode字典解析文章的规则
        byte[] utf8 = {
                (byte) 0b00000001,
                (byte) 0b11000010, (byte) 0b10100101,
                (byte) 0b11100110, (byte) 0b10010110, (byte) 0b10110000
        };
        System.out.println(new String(utf8, "UTF-8"));

    }

}


